/**
 * 图书实体模型
 */
export class Book {
  constructor(data = {}) {
    this.isbn = data.isbn || '';
    this.title = data.title || '';
    this.author = data.author || '';
    this.publisher = data.publisher || '';
    this.publicationDate = data.publicationDate || null;
    this.placeOfPublication = data.placeOfPublication || '';
    this.size = data.size || '';
    this.classificationNo = data.classificationNo || '';
    this.subject = data.subject || '';
    this.series = data.series || '';
    this.requisitionNo = data.requisitionNo || '';
    this.pageNo = data.pageNo || '';
    this.price = data.price || '';
    this.requestNo = data.requestNo || '';
    this.barcodeNo = data.barcodeNo || '';
    this.currentLocation = data.currentLocation || '';
    this.currentLocation2 = data.currentLocation2 || '';
    this.collectionStatus = data.collectionStatus || '';
    this.circulationCategory = data.circulationCategory || '';
  }

  /**
   * 获取格式化后的出版年份
   * @returns {string} 格式化后的年份
   */
  getFormattedPublicationDate() {
    if (!this.publicationDate) return '未知';
    return String(this.publicationDate);
  }

  /**
   * 获取书籍的完整信息描述
   * @returns {string} 书籍信息描述
   */
  getFullDescription() {
    return `《${this.title}》 - ${this.author || '未知作者'}, ${this.getFormattedPublicationDate()}年, ${this.publisher || '未知出版社'}`;
  }

  /**
   * 从API响应创建Book对象
   * @param {Object} data - API返回的数据
   * @returns {Book} 创建的Book对象
   */
  static fromApiResponse(data) {
    return new Book(data);
  }

  /**
   * 从API响应数组创建Book对象数组
   * @param {Array} dataArray - API返回的数据数组
   * @returns {Array<Book>} 创建的Book对象数组
   */
  static fromApiResponseArray(dataArray) {
    if (!Array.isArray(dataArray)) return [];
    return dataArray.map(data => Book.fromApiResponse(data));
  }
}
